$(function () {
    let inputUtil = new Input_util();
    inputUtil.popUpsView();
    inputUtil.popUpsInsert();
    let popUpsDown = $(".pop-ups-down");
    let recycle = $(".recycle");
    popUpsDown.on("click", function () {
        $(".recycle-bin-window").css("display", "none")
    })
    recycle.on("click", function () {
        $(".recycle-bin-window").css("display", "block")
    })
    $(".search-img").on("click", function () {
        const val = $(".search-input input").val()
        window.location.href = "/www.xiaomi.com/background/home?menuId=107&activityMc=" + val;
    })
    $("#date-flashback").on("click", function () {
        const activityDate = $("#date-flashback").val()
        window.location.href = "/www.xiaomi.com/background/home?menuId=107&activityDate=" + activityDate;
    })
    $("#date-positive-order").on("click", function () {
        let activityDate = $("#date-positive-order").val()
        window.location.href = "/www.xiaomi.com/background/home?menuId=107&activityDate=" + activityDate;
    })
    $(".select").on("click", function () {
        const dateBegin = $("#dateBegin").val()
        const dateEnd = $("#dateEnd").val()
        const messageType = $("#type").val()
        window.location.href = "/www.xiaomi.com/background/home?menuId=107&dateBegin=" + dateBegin + "&dateEnd=" + dateEnd + "&messageType=" + messageType;
    })
    $(".publish").on("click", function () {
        const messageTitle = $("#messageTitle").val()
        const messageContext = $("#messageContext").val()
        const addType = $("#addType").val()
        console.log(messageTitle)

        if (messageTitle.trim() != null && messageContext.trim() != null) {
            let messageJson = {
                messageTitle: messageTitle,
                messageContext: messageContext,
                messageType: addType
            }
            let message = new Message();
            message.addMessage(messageJson).then(res => {
                console.log(res)
                location.reload();
            })
        }
    })
    $(".cancel").on("click", function () {
        $(".add-window").css("display", "none")
    })
    $(".leave").on("click",function (){
        const messageId=$(this).attr("message-id")
        console.log(messageId)
        let message = new Message();
        message.deleteMessage(messageId).then(res => {
            console.log(res)
            location.reload();
        })
    })
})